function fn() {
    $.ajax({
        type: 'post',
        url: 'http://47.94.4.201/index.php/index/index/register',
        data: {
            name: $('input:eq(0)').val(),
            pwd: $('input:eq(1)').val(),
            emails: $('input:eq(2)').val()
        },
        dataType: 'json',
        success: (data) => {
            if (data.msg == '添加成功') {
                location.assign('./登录.html')
                console.log(data);
            } else {
                alert('用户名重复')
            }
        },
        error: (e) => {
            console.log(e);
        }
    })
}

// 用户名
var user_name = document.querySelectorAll('input')[0]
var reg0 = /^[\u4e00-\u9fa5]{4,10}$/
user_name.addEventListener('blur', () => {
    if (!reg0.test(event.target.value)) {
        event.target.nextElementSibling.style.display = 'block'
    } else {
        event.target.nextElementSibling.style.display = 'none'
    }
})

// 密码
var user_password = document.querySelectorAll('input')[1]
var reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,10}$/;
user_password.addEventListener('blur', () => {
    if (!reg.test(event.target.value)) {
        event.target.nextElementSibling.style.display = 'block'
    } else {
        event.target.nextElementSibling.style.display = 'none'
    }
})

// 邮箱
var user_eamil = document.querySelectorAll('input')[2]
var reg2 = /^([A-Za-z0-9_\-\.])+@([A-Za-z0-9_\-\.])+\.[A-Za-z]{2,4}$/
user_eamil.addEventListener('blur', () => {
    if (!reg2.test(event.target.value)) {
        event.target.nextElementSibling.style.display = 'block'
    } else {
        event.target.nextElementSibling.style.display = 'none'
    }
})

